version: '3.4'

services:
  storage:
    container_name: messenger-storage
    image: postgres:14
    restart: always
    command: [ "postgres", "-c", "log_statement=mod" ]
    ports:
      - "7432:5432"
    environment:
      POSTGRES_DB: $POSTGRES_DATABASE_NAME
      POSTGRES_USER: $POSTGRES_USER
      POSTGRES_PASSWORD: $POSTGRES_PASSWORD
    volumes:
      - ~/volumes/messenger:/var/lib/postgresql/data
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -d ${POSTGRES_DATABASE_NAME} -U ${POSTGRES_USER}" ]
      interval: 10s
      timeout: 5s
      retries: 10

  app:
    container_name: messenger-app
    restart: always
    build:
      context: .
      dockerfile: ./Dockerfile
    depends_on:
      storage:
        condition: service_healthy
      file_system:
        condition: service_started
    ports:
      - "${APP_HTTP_PORT}:80"
      - "${APP_HTTPS_PORT}:443"
    environment:
      ASPNETCORE_ENVIRONMENT: $ASPNETCORE_ENVIRONMENT
      ASPNETCORE_URLS: https://+;http://+;
      ASPNETCORE_Kestrel__Certificates__Default__Path: /https/aspnetapp.pfx
      ASPNETCORE_Kestrel__Certificates__Default__Password: $ASPNETCORE_Password
    stdin_open: true
    tty: true
    volumes:
      - type: bind
        source: $CERTIFICATE_PATH
        target: /https/
